home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -serious- / programming / other / pmdev / e / demos / disable.e < prev    next >
Encoding:
Text File  |  2000-02-28  |  4.8 KB  |  136 lines

  1. /* -- ----------------------------------------------------------------- -- *
  2.  * -- Program.....: Disable.e                                           -- *
  3.  * -- Author......: Daniel Kasmeroglu <raptor@cs.tu-berlin.de>          -- *
  4.  * -- Description.: Port of an example by Henrik Isaksson.              -- *
  5.  * -- ----------------------------------------------------------------- -- *
  6.  * -- Original header:                                                  -- *
  7.  * --                                                                   -- *
  8.  * --   $VER: Disable.c 2.0 (05.09.98)                                  -- *
  9.  * --                                                                   -- *
  10.  * --   Popup Menu example program                                      -- *
  11.  * --                                                                   -- *
  12.  * --   ©1996-1997 Henrik Isaksson                                      -- *
  13.  * --   All Rights Reserved.                                            -- *
  14.  * --                                                                   -- *
  15.  * --   Run and click the mouse in the window!                          -- *
  16.  * --                                                                   -- *
  17.  * -- ----------------------------------------------------------------- -- */
  18.  
  19. /* -- ----------------------------------------------------------------- -- *
  20.  * --                              Options                              -- *
  21.  * -- ----------------------------------------------------------------- -- */
  22.  
  23. OPT PREPROCESS       -> enable preprocessor
  24.  
  25.  
  26. /* -- ----------------------------------------------------------------- -- *
  27.  * --                              Modules                              -- *
  28.  * -- ----------------------------------------------------------------- -- */
  29.  
  30. MODULE 'libraries/popupmenu' ,
  31.        'intuition/intuition' ,
  32.        'utility/tagitem'
  33.  
  34. MODULE 'popupmenu'
  35.  
  36.  
  37. /* -- ----------------------------------------------------------------- -- *
  38.  * --                               Main                                -- *
  39.  * -- ----------------------------------------------------------------- -- */
  40.  
  41. ->»» PROC main
  42. PROC main()
  43. DEF ma_window : PTR TO window
  44. DEF ma_menu   : PTR TO popupmenu
  45. DEF ma_imsg1  : PTR TO intuimessage
  46. DEF ma_imsg2  : intuimessage
  47. DEF ma_result
  48.  
  49.   ma_result := TRUE
  50.  
  51.   popupmenubase := OpenLibrary( 'popupmenu.library', 9 )
  52.   IF popupmenubase <> NIL
  53.  
  54.     -> Create a very simple menu...
  55.     ma_menu := PMMenu( 'Plain Simple Menu !' ),
  56.                  PMCheckItem( 'Enable quit?', 10 ), PMEnd,
  57.                  PMBar, PMEnd,
  58.                  PMItem( 'Quit' ),
  59.                    PMSimpleSub,
  60.                      PMItem( 'Quit' ), PM_DISABLED,TRUE, PM_USERDATA, 5, PM_ID, 15, PMEnd,
  61.                    PMEnd,
  62.                  PMEnd,
  63.                End
  64.  
  65.     IF ma_menu <> NIL
  66.  
  67.       -> Open a little window
  68.       ma_window := OpenWindowTagList( NIL,
  69.       [ WA_IDCMP       , IDCMP_CLOSEWINDOW OR IDCMP_MOUSEBUTTONS ,
  70.         WA_RMBTRAP     , TRUE               ,
  71.         WA_DRAGBAR     , TRUE               ,
  72.         WA_WIDTH       , 150                ,
  73.         WA_HEIGHT      , 100                ,
  74.         WA_LEFT        , 0                  ,
  75.         WA_TOP         , 0                  ,
  76.         WA_TITLE       , 'Disable & Enable' ,
  77.         WA_CLOSEGADGET , TRUE               ,
  78.         TAG_END ] )
  79.  
  80.       IF ma_window <> NIL
  81.  
  82.         WHILE ma_result <> FALSE
  83.  
  84.           -> Wait for a message
  85.           WaitPort( ma_window.userport )
  86.  
  87.           -> Get the message
  88.           WHILE (ma_imsg1 := GetMsg( ma_window.userport )) <> NIL
  89.  
  90.             CopyMem( ma_imsg1, ma_imsg2, SIZEOF intuimessage )
  91.             ReplyMsg( ma_imsg1 )
  92.  
  93.             IF ma_imsg2.class = IDCMP_CLOSEWINDOW
  94.               ma_result := FALSE
  95.             ELSEIF ma_imsg2.class = IDCMP_MOUSEBUTTONS
  96.  
  97.               ma_result := Pm_OpenPopupMenuA( ma_window,
  98.               [ PM_MENU,   ma_menu       ,
  99.                 PM_CODE,   ma_imsg2.code ,
  100.                 TAG_END ] ) - 5
  101.                                                                                 
  102.               -> See if "Enable quit?" is checked
  103.               IF Pm_ItemChecked( ma_menu, 10 ) <> FALSE
  104.                 -> Find the item and enable it
  105.                 Pm_SetItemAttrsA( Pm_FindItem( ma_menu, 15 ), [ PM_DISABLED, FALSE, TAG_END ] )
  106.               ELSE
  107.                 -> Find the item and disable it
  108.                 Pm_SetItemAttrsA( Pm_FindItem( ma_menu, 15 ), [ PM_DISABLED, TRUE, TAG_END ] )
  109.               ENDIF
  110.  
  111.             ENDIF
  112.  
  113.           ENDWHILE
  114.  
  115.         ENDWHILE
  116.         CloseWindow( ma_window )
  117.  
  118.       ELSE
  119.         PrintF( 'Window error !\n' )
  120.       ENDIF
  121.  
  122.       Pm_FreePopupMenu( ma_menu )
  123.  
  124.     ELSE
  125.       PrintF( 'Menu error !\n' )
  126.     ENDIF
  127.  
  128.     CloseLibrary( popupmenubase )
  129.  
  130.   ELSE
  131.     PrintF( 'Cannot open "popupmenu.library" v9+ !\n' )
  132.   ENDIF
  133.  
  134. ENDPROC
  135. ->»»>
  136.